//基于 Promise封装的微信小程序API

//获取用户授予过的权限
export function z_getSetting() {
  return new Promise( (resolve, reject) =>{
    wx.getSetting({
      success: (result)=>{
        resolve(result)
      },
      fail: (error)=>{
        reject(error)
      },
    });
  })

}

//打开用户授权过的授权信息
export function z_openSetting() {
  return new Promise((resolve, reject) => {
    wx.openSetting({
      success: (result)=>{
        resolve(result)
      },
      fail: (error)=>{
        reject(error)
      }
    })
  })
}

//获取用户收货地址
export function z_chooseAddress() {
  return new Promise((resolve, reject) => {
    wx.chooseAddress({
      success: (result)=>{
        resolve(result)
      },
      fail: (error)=>{
        resolve(error)
      }
    });
  })
}

//wx-login
export function z_login() {
  return new Promise((resolve, reject) => {
    wx.login({
      timeout:10000,
      success: (result)=>{
        resolve(result)
      },
      fail: (error)=>{
        reject(error)
      }
    });
  })
}

//支付接口
export function z_requestPayment(pay) {
  return new Promise((resolve, reject) => {
    wx.requestPayment({
      // timeStamp: '',
      // nonceStr: '',
      // package: '',
      // signType: '',
      // paySign: '',
      ...pay,
      success: (result)=>{
        resolve(result)
      },
      fail: (error)=>{
        reject(error)
      }
    });
  })
}
